package com.ylb.rent.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.xiaoleilu.hutool.util.CollectionUtil;
import com.ylb.rent.dao.StuffMapper;
import com.ylb.rent.entity.Stuff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 import com.ylb.rent.dao.RoomStuffMapper;
import  com.ylb.rent.entity.RoomStuff;
import com.ylb.rent.service.IRoomStuffService;

/**
 * 房间设施Service业务层处理
 * 
 * @author ylb
 * @date 2023-06-29
 */
@Service
public class RoomStuffServiceImpl implements IRoomStuffService 
{
    @Autowired
    private RoomStuffMapper roomStuffMapper;

    @Autowired
    private StuffMapper stuffMapper;

    @Override
    public List<Stuff> selectStuffListByRoomId(long roomId) {
        RoomStuff build = RoomStuff.builder().roomId(roomId).build();
        List<RoomStuff> roomStuffs = roomStuffMapper.selectRoomStuffList(build);
        List<Long> stuffIdList = roomStuffs.stream().map(RoomStuff::getStuffId).collect(Collectors.toList());
        if(CollectionUtil.isNotEmpty(stuffIdList)){
            return stuffMapper.selectBatchIds(stuffIdList);
        }
        return new ArrayList<>();


    }

    /**
     * 查询房间设施
     * 
     * @param id 房间设施主键
     * @return 房间设施
     */
    @Override
    public RoomStuff selectRoomStuffById(Long id)
    {
        return roomStuffMapper.selectRoomStuffById(id);
    }

    /**
     * 查询房间设施列表
     * 
     * @param roomStuff 房间设施
     * @return 房间设施
     */
    @Override
    public List<RoomStuff> selectRoomStuffList(RoomStuff roomStuff)
    {
        return roomStuffMapper.selectRoomStuffList(roomStuff);
    }

    /**
     * 新增房间设施
     * 
     * @param roomStuff 房间设施
     * @return 结果
     */
    @Override
    public int insertRoomStuff(RoomStuff roomStuff)
    {
        return roomStuffMapper.insertRoomStuff(roomStuff);
    }

    /**
     * 修改房间设施
     * 
     * @param roomStuff 房间设施
     * @return 结果
     */
    @Override
    public int updateRoomStuff(RoomStuff roomStuff)
    {
        return roomStuffMapper.updateRoomStuff(roomStuff);
    }

    /**
     * 批量删除房间设施
     * 
     * @param ids 需要删除的房间设施主键
     * @return 结果
     */
    @Override
    public int deleteRoomStuffByIds(Long[] ids)
    {
        return roomStuffMapper.deleteRoomStuffByIds(ids);
    }

    /**
     * 删除房间设施信息
     * 
     * @param id 房间设施主键
     * @return 结果
     */
    @Override
    public int deleteRoomStuffById(Long id)
    {
        return roomStuffMapper.deleteRoomStuffById(id);
    }
}
